<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="saveData()">点击保存数据</button>
    <button onclick="deleteData()">点击删除数据</button>
    <button onclick="readData()">点击读取数据</button>
    <button onclick="clearAll()">清空数据</button>
    
    <script type="text/javascript">
        let p = {name:'zw',age:18}
        function saveData(){
            sessionStorage.setItem('msg','hello')
            sessionStorage.setItem('msg2',JSON.stringify(p))
        }
        function deleteData(){
            sessionStorage.removeItem('msg')
        }
        function readData(){
            console.log(sessionStorage.getItem('msg'))
            const result = sessionStorage.getItem('msg2')
            console.log(JSON.parse(result))
        }
        function clearAll(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>